import 'package:flutter/material.dart';
import 'package:schedule_self_client/ui/pages/calendar_page.dart';
import 'package:schedule_self_client/ui/pages/report_page.dart';
import 'package:schedule_self_client/ui/pages/task_list_page_v2.dart';
import 'package:schedule_self_client/ui/pages/tomato_clock_page.dart';
import 'package:schedule_self_client/ui/pages/user_center_page.dart';

class AppLayout extends StatefulWidget {
  const AppLayout({super.key});

  @override
  State<AppLayout> createState() => _AppLayoutState();
}

class _AppLayoutState extends State<AppLayout> {
  late final PageController _pageController;
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
    _pageController = PageController(initialPage: _currentIndex);
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: PageView(
          controller: _pageController,
          children: const [
            TaskListPageV2(),
            CalendarPage(),
            TomatoClockPage(),
            ReportPage(),
            UserCenterPage(),
          ],
          onPageChanged: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.task), label: '待办列表'),
          BottomNavigationBarItem(
              icon: Icon(Icons.calendar_month), label: '日历'),
          BottomNavigationBarItem(icon: Icon(Icons.timer), label: '番茄时钟'),
          BottomNavigationBarItem(icon: Icon(Icons.insert_chart), label: '报表'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: '用户中心'),
        ],
        onTap: (index) {
          setState(() {
            _currentIndex = index;
            _pageController.jumpToPage(index);
          });
        },
      ),
    );
  }
}
